//
//  ShopCarBottomView.m
//  Mall
//
//  Created by 孙飞燕 on 16/10/13.
//  Copyright © 2016年 孙飞燕. All rights reserved.
//

#import "ShopCarBottomView.h"
#import "ShoppingCarBottomModel.h"
@implementation ShopCarBottomView

- (instancetype)initWithFrame:(CGRect)frame withModel:(ShoppingCarBottomModel *)bottomModel{
    self = [super initWithFrame:frame];
    if (self) {
        _allSelectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_allSelectBtn setImage:[UIImage imageNamed:@"btn_selected_default"] forState:UIControlStateNormal];
        [_allSelectBtn setImage:[UIImage imageNamed:@"btn_selected"] forState:UIControlStateSelected];
        [_allSelectBtn addTarget:self action:@selector(allSelectAction:) forControlEvents:UIControlEventTouchUpInside];
        _allSelectBtn.frame = CGRectMake(10, 10, 20, 20);
        [self addSubview:_allSelectBtn];


        UILabel *allSelectLabel = [[UILabel alloc]init];
        allSelectLabel.text = @"全选";
        allSelectLabel.textColor = [UIColor blackColor];
        allSelectLabel.font = [UIFont systemFontOfSize:12];
        allSelectLabel.textAlignment = 0;
        allSelectLabel.frame = CGRectMake(40, 10, 60, 20);
        [self addSubview:allSelectLabel];

        _resultPrice = [[UILabel alloc]init];
        _resultPrice.font = allSelectLabel.font;
        _resultPrice.textAlignment = 0;
        _resultPrice.textColor = [UIColor blueColor];
         _resultPrice.text = @"0.0";
        _resultPrice.frame = CGRectMake(CGRectGetWidth(self.frame)/2, 10, 80, 30);
        [self addSubview:_resultPrice];

        UIButton *endBtn = [UIButton buttonWithType:UIButtonTypeSystem];
        endBtn.backgroundColor = [UIColor redColor];
        NSString *endStr = [NSString stringWithFormat:@"结算(共%d件)",bottomModel.counts];
        endBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        [endBtn setTitle:endStr forState:UIControlStateNormal];
        endBtn.frame = CGRectMake(270, 0, self.frame.size.width - 270, self.frame.size.height);
        [self addSubview:endBtn];
    }
    return self;
}

//全选点击
- (void)allSelectAction:(UIButton *)sender{
    if ([self.delegate respondsToSelector:@selector(shopCarBottomViewDelegate:withView:)]) {
        [self.delegate shopCarBottomViewDelegate:sender withView:self];
    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
